define(["jquery","template","comm/code/code","comm/simple/simple"],function($,template,$code,$simple){
	var print = {};

	/**
	 * 处理答案
	 */
	var handleValues = function(values,time){
		for(var key in values){
			if( key == "anamnesis" ) values[key] = JSON.parse(values[key]);
		}
		if( values.birthday ) values.age = $simple.dateDiff(values.birthday,time).age;
		return values;
	}

	/**
	 * 格式化
	 */
	var formatValues = function(options){
		var data = $code.getDeCodes();
		var obj = {};
		for(var key in options.values){
			for(var item in data){
				if( key == data[item] ){
					obj[item] = options.values[key];
					break;
				}
			}
		}
		obj = handleValues(obj,options.time);
		return obj;
	}

	/**
	 * 初始化ui
	 */
	var initUi = function(options,tmp,css){
		var data = formatValues(options);
		$("#" + options.id).html( tmp );
		var html = template("tpl_print_" + options.tmpId,data);
		$("#" + options.id).html(html);
		$("#" + options.id).append('<style>'+css+'</style>');
	}

	/**
	 * 初始化
	 * id：			dom元素的id
	 * tmpId：		打印模板id
	 * values：     答案
	 * time:        建档时间
	 */
	print.init = function(options){
		var tmp = "text!comm/print/templates/print_" + options.tmpId + "/tmp.html";
		var css = "text!comm/print/templates/print_" + options.tmpId + "/tmp.css";
		require([tmp,css],function(tmp,css){
			initUi(options,tmp,css);
		});
	}

	return print;
});